// Copyright 2019 The rhyme_lph Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// U [author] rhyme_lph
// u [email]  rhymelph@gmail.com
// d [github] https://github.com/rhymelph

import 'package:base_plugin/base_plugin.dart';
import 'package:finance_app/src/common/config.dart';
import 'package:finance_app/src/entities/setting_app_entity.dart';
import 'package:finance_app/src/mixin/search_data_list_mixin.dart';
import 'package:finance_app/src/utils/reg_exp_utils.dart';
import 'package:flutter/material.dart';
import 'package:finance_app/src/page/setting/industry_select_page.dart';

class IndustrySelectProvider extends BaseProvider with SearchDataListMixin {
  SettingAppIndustryType currentSelect;
  List<SettingAppIndustryType> searchList = [];

  @override
  void initState() {
    super.initState();
    searchList = List.from(Config.settingApp.industryType.where((element) =>
        element.businessType == Config.currentCompany.businessType));
  }

  @override
  Future get dataFuture => null;

  @override
  void searchRefreshData(data) {
    searchList = List.from(Config.settingApp.industryType
        .where((element) =>
            RegExpUtils.getSearchRegExp(data).hasMatch(element.name))
        .toList());
    update();
  }

  onSelectType(SettingAppIndustryType e) {
    if (e == currentSelect) return;
    currentSelect = e;
    obtainContext?.call((context) {
      Navigator.of(context).pop(currentSelect);
    });
  }
}
